<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>view/workArea/plan/expectedDoor</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="../../../css/mui.min.css">
		<link rel="stylesheet" href="../../../css/global.css">
		<link rel="stylesheet" href="../../../css/style.css">
		<link href="../../../css/task.css" rel="stylesheet" />
		<style type="text/css">
			#div {
				width: 0px;
				height: 0px;
				background: red;
				position: fixed;
				top: 65%;
				left: 50%;
			}
			/*移除底部或顶部三角,需要在删除此代码*/
			.mui-popover .mui-popover-arrow:after {
				width: 0px;
			}
			.customerName {
				width: 50%;
				display: block;
				float: right;
				color: #333333;
				text-align: right;
				line-height: initial;
			}
		</style>
	</head>

	<body>
		
		<div id="div"></div>
		<div id="popover" class="mui-popover shadow popover">
			<p class="title" id="title">与您之前的工作计划时间冲突，是否确定？</p>
			<div class="btn_box">
				
				<span class="fl" onclick="closepop()">取消</span>
				<span class="fr red" id="quedingupdate">确定</span>
			</div> 
		</div>
		
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">更改预计上门时间</h1>
		</header>
		<div class="mui-content">
			<div class="details_con">
				<!-- <div class="my-content-cell">
					<div class="inline-block" id="pjcgqd">
						<em>查看计划安排</em>
						<span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
					</div>
				</div> -->
				<div class="clum" style="height: auto; padding: 13px 0;">
					<span class="name" style="line-height: initial; padding-right: 10px;">客户名称</span>
					<span id="customerName" class="customerName"></soan>
				</div>
				<div class="clum">
					<span class="name">预计上门时间<em class="t_red">*</em></span>
					<input id="estimatedVisitingTime" class="d_ipt" readonly="readonly" placeholder="请选择时间"/>
					<!-- <button id='estimatedVisitingTime' type="button" class="selectDate">请选择时间</button> -->
				</div>
				<div class="clum">
					<span class="name">预计工时<em class="t_red">*</em></span>
					<input id="estimatedWorkingHours" type="number" class="d_ipt" placeholder="请输入预计工时" onchange="jisuan('1')"/>
				</div>
				<div class="clum">
					<span class="name">预计离开时间<em class="t_red">*</em></span>
					<input id="estimatedDepartureTime" class="d_ipt" placeholder="自动计算" disabled="disabled"/> 
				</div>
			</div>
			<div class="btn_box">
				<span class="fl" id="cancel">取消</span>
				<span class="fr red" id="save">保存</span>
			</div>
			<div style="height: 50px;"></div>
		</div>

		<!-- js代码 start -->

		<!-- 基础js start -->
		<script src="../../../js/mui.min.js"></script>
		<script src="../../../js/utils/h.js"></script>
		<script src="../../../js/constant.js"></script>
		<script src="../../../js/common.js"></script>
		<script src="../../../js/utils/base64.js"></script>
		<script src="../../../js/utils/md5.js"></script>
		<script src="../../../js/utils/sortMap.js"></script>
		<script src="../../../js/utils/http.js"></script>
		<script src="../../../js/app.js"></script>
		<!-- 基础js end -->
		<script src="../../../js/utils/rolldate.min.js"></script>
		
		<script type="text/javascript" charset="utf-8">
			var saveIn;
			var planIds = "";
			var customerName = "";
			var estimatedVisitingTime = "";
			var estimatedWorkingHours = "";
			var estimatedDepartureTime = "";
			var ServiceNoticeId
			var serviceNo
			var serviceRole
			
			 //mui初始化
			(function($, doc) {
				$.init();
				
				// 取消方法
				h("#cancel").tap(function(){
					$.back()
				});
				
				new Rolldate({
					el: '#estimatedVisitingTime',
					format: 'YYYY-MM-DD hh:mm',
					beginYear: 2015,
					endYear: 2050,
					trigger: 'click',
					lang: {
						title: '请选择预计上门时间',
					},
					confirm: function(date) {
						jisuan(date)
					}
				})
				
			
				$.plusReady(function() {
					
					var self = plus.webview.currentWebview();
					// 获取上一个页面传过来的参数并显示到页面
					planIds = self.planIds;
					customerName = self.customerName;
					estimatedVisitingTime = self.estimatedVisitingTime;
					estimatedWorkingHours = self.estimatedWorkingHours;
					estimatedDepartureTime = self.estimatedDepartureTime;
					h("#customerName").html(customerName);
					h("#estimatedVisitingTime").val(estimatedVisitingTime);
					h("#estimatedWorkingHours").val(estimatedWorkingHours);
					h("#estimatedDepartureTime").val(estimatedDepartureTime);
					
					// 保存
					h("#save").tap(function() {
						estimatedVisitingTime = h("#estimatedVisitingTime").val();
						estimatedWorkingHours = h("#estimatedWorkingHours").val();
						estimatedDepartureTime = h("#estimatedDepartureTime").val();
						
						var evt = stringYYYYMMDDHHMMToDate(estimatedVisitingTime).getTime();
						var newDate = new Date().getTime();
						if(evt <= newDate){
						    app.closeWaiting()
						    app.toast("预计上门时间不可以小于当前时间");	
							return		   
						};
						
						// 调用计算方法
						jisuan('1');
						if(estimatedVisitingTime==null || estimatedVisitingTime=="" || estimatedVisitingTime=="请选择时间"){
							app.toast("请选择预计上门时间");
							return
						}
						
						if(estimatedWorkingHours==null || estimatedWorkingHours==""){
							app.toast("请选择预计工时");
							return
						}
						
						ajaxGet(BASE_URL + "cc/PlanDetails/checkPlanDetailsList", {
							"enginnerId": app.getUser().enginnerId,
							"estimatedVisitingTime": estimatedVisitingTime,
							"estimatedDepartureTime": estimatedDepartureTime,
							"planId": planIds
						}, function(data) {
							 if(data.code==200){
								saveIn()
							 }else{
								 app.closeWaiting()
								 mui("#popover").popover('toggle', document.getElementById("div"));
							 }
						}, function(errorMsg) {
							app.closeWaiting()
							app.toast(errorMsg)
							console.log(JSON.stringify(errorMsg))
						});


						// ajaxPost(BASE_URL + "cc/planAndCase/updatePlan", {
						// 	"estimatedVisitingTime": estimatedVisitingTime,//预计上门时间
						// 	"estimatedWorkingHours": estimatedWorkingHours,//预计工时
						// 	"estimatedDepartureTime": estimatedDepartureTime,//预计离开时间
						// 	"planIds": planIds
						// }, function(data) {
						// 	// console.log(JSON.stringify(data))
						// 	if(data.code==200){
						// 		app.toast("保存成功");
						// 		// 返回上一页并刷新
						// 		var priorPage = plus.webview.getWebviewById('view/workArea/plan/workPlan');
						// 		priorPage.evalJS('selectList()')
						// 		self.close();
						// 	}
						// }, function(errorMsg) {
						// 	console.log(JSON.stringify(errorMsg))
						// });
						
					});
					
					// 查看计划安排
					h("#pjcgqd").tap(function() {
						app.toast("暂未开放")
					});
					
					h("#quedingupdate").tap(function(){
						 saveIn()
					})
					
					saveIn = function(){
						app.showWaiting('正在提交...')
						ajaxPost(BASE_URL + "cc/planAndCase/updatePlan", {
							"estimatedVisitingTime": estimatedVisitingTime,//预计上门时间
							"estimatedWorkingHours": estimatedWorkingHours,//预计工时
							"estimatedDepartureTime": estimatedDepartureTime,//预计离开时间
							"planIds": planIds
						}, function(data) {
							app.closeWaiting()
							// console.log(JSON.stringify(data))
							if(data.code==200){
								app.toast("保存成功");
								// 返回上一页并刷新
								var priorPage1 = plus.webview.getWebviewById('view/workArea/plan/workPlan');
								if (priorPage1) {
									priorPage1.evalJS('selectList()')
								}
								var priorPage2 = plus.webview.getWebviewById('view/workArea/plan/workPlanMore');
								if (priorPage2) {
									priorPage2.evalJS('selectList()')
								}
								var priorPage3 = plus.webview.getWebviewById('view/service/taskDetails/task_details.html');
								if (priorPage3) {
									priorPage3.evalJS('selectList()')
								}
								self.close();
								mui.back();
							}
						}, function(errorMsg) {
							app.closeWaiting()
							console.log(JSON.stringify(errorMsg))
						});
					}
					
				});
			}(mui, document));
						
			function closepop(){
				mui("#popover").popover('hide', document.getElementById("div"));
			}
			
			// 自动计算方法
			function jisuan(date){
				var estimatedVisitingTime;
				if(date!="1"){
					estimatedVisitingTime = date
				}else{
					estimatedVisitingTime = h("#estimatedVisitingTime").val();
				}
				if(estimatedVisitingTime==null || estimatedVisitingTime=="" || estimatedVisitingTime=="请选择时间"){
					return
				}
				var evt = stringYYYYMMDDHHMMToDate(estimatedVisitingTime).getTime();
				var estimatedWorkingHours = h("#estimatedWorkingHours").val();
				if(estimatedWorkingHours==null || estimatedWorkingHours==""){
					return
				}
				var edt = evt + estimatedWorkingHours * 60 *60 * 1000;
				var estimatedDepartureTime = new Date(edt).Format("yyyy-MM-dd HH:mm");
				h("#estimatedDepartureTime").val(estimatedDepartureTime);
			}
			
		</script>
		<!-- js代码 end -->

	</body>

</html>
